﻿@using System.Collections
@using System.Web.UI.WebControls
@using WSS.Pub
@{
    ViewBag.Title = "SetResOpt";
}
@section css
{
    <style type="text/css">
        .div_Opt
        {
            margin: 7px;
        }

        .checkbox
        {
            width: 100px;
            float: left;
        }

        body
        {
            padding-top: 5px;
        }

        .btn-lg
        {
            font-size: 14px;
            line-height: 40px;
            height: 40px;
            width: 130px;
            margin-right: 7px;
        }

        #div_Header button
        {
            padding: 0;
        }

        .panel-body
        {
            padding: 2px;
        }
    </style>
}
@section script
{
    <script type="text/javascript">
        $(function() {
            chooseOptType('@ViewBag.OptTypes');

            $("#div_Header button").click(function() {
                $(this).siblings().attr("class", "btn btn-default btn-lg");
                $(this).attr("class", "btn  btn-success btn-lg");
                chooseOptType($(this).attr("optVal"));
            });
        });

        function chooseOptType(optType) {
            if (optType.indexOf("PERSON") > -1 || optType.indexOf("HOSPITAL") > -1 || optType.indexOf("MYSET") > -1) {
                $("#div_Header button[optVal='MYSET']").attr("class", "btn btn-success btn-lg");
                $("#div_Content").show();
            } else if (optType.indexOf("OPEN") > -1 || optType.indexOf("CLOSE") > -1) {
                $("#div_Header button[optVal='" + optType + "']").attr("class", "btn  btn-success btn-lg");
                $("#div_Content").hide();
            }
        }

        /*
         保存数据
        */
        function save() {
            var optType = new Array();
            var optUserData = new Array();
            var optHospData = new Array();
            var curChooseOptType = $("#div_Header button[class*='btn-success']").attr("optVal");

            if ($("#div_Header button[class*='btn-success']").size() == 0) {
                mainfn.msg("您当前未选取任何权限！");
                return false;
            }
            //若选择自定义，获取选取的用户和医院信息
            if (curChooseOptType == "MYSET") {
                window.frames["iframe_userChoose"].$("#Ul_ChoosedData li").each(function() {
                    optUserData.push($(this).attr("detailID"));
                });
                window.frames["iframe_hospChoose"].$("#Ul_Hosp_ChoosedData li").each(function() {
                    optHospData.push($(this).attr("detailID"));
                });
                if (optHospData.length == 0 && optUserData.length == 0) {
                    mainfn.msg("自定义权限，请选取指定的用户或者医院！");
                    return false;
                } else if (optHospData.length == 0 && optUserData.length != 0) {
                    optType.push("PERSON");
                } else if (optHospData.length != 0 && optUserData.length == 0) {
                    optType.push("HOSPITAL");
                } else {
                    optType.push("PERSON");
                    optType.push("HOSPITAL");
                }

            } else {
                optType.push(curChooseOptType);
            }
            $.ajax({
                url: '/ResCenter/SaveResOpt',
                data: { resno: '@ViewBag.ResNo', opttype: optType.join(','), optuserdata: optUserData.join(','), opthospdata: optHospData.join(',') },
                type: 'POST',
                dataType: 'json',
                success: function(data) {
                    mainfn.msg(data.msg);
                    setTimeout(function() {
                        parent.$("#btn_Cancel").click();
                    }, 2000);
                }
            });
        }
    </script>
}

<div class="div_Opt">

    <div id="div_Header">
        <button type="button" class="btn btn-default btn-lg" optval="OPEN">所有人</button>
        <button type="button" class="btn btn-default btn-lg" optval="CLOSE">仅自己</button>
        <button type="button" class="btn btn-default btn-lg" optval="MYSET">自定义</button>
    </div>
    <div id="div_Content" style="display: none; height: 445px; padding-top: 5px">
        <div class="panel-group" id="accordion">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        <a data-toggle="collapse" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
                            <span style="font-size: 14px;">指定用户</span>
                        </a>
                    </h4>
                </div>
                <div id="collapseOne" class="panel-collapse collapse in">
                    <div class="panel-body">
                        <iframe src="/rescenter/UsersList/@ViewBag.ResNo"  name="iframe_userChoose" width="750px" height="330px" scrolling="auto" marginwidth="0" framespacing="0" marginheight="0" frameborder="0"></iframe>
                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        <a data-toggle="collapse" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
                            <span style="font-size: 14px;">指定医院</span>
                        </a>
                    </h4>
                </div>
                <div id="collapseTwo" class="panel-collapse collapse">
                    <div class="panel-body">
                        <iframe src="/rescenter/HospList/@ViewBag.ResNo"  name="iframe_hospChoose" width="750px" height="330px" scrolling="auto" marginwidth="0" framespacing="0" marginheight="0" frameborder="0"></iframe>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

